<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }
        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>系统设置
            <small>角色管理</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>系统设置</el-breadcrumb-item>
            <el-breadcrumb-item>角色管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="编码/名称/助记码" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="name" label="角色名称" align="center"></el-table-column>
                <el-table-column prop="keyword" label="keyword" align="center"></el-table-column>
                <el-table-column prop="description" label="说明" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleEdit(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增菜单" :visible.sync="dialogFormVisible">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <template>
                            <el-tabs v-model="activeName" type="card">
                                <el-tab-pane label="基本信息" name="first">
                                    <el-form label-position="right" label-width="100px">
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="角色名称" prop="name">
                                                    <el-input v-model="formData.name"/>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="keyword" prop="keyword">
                                                    <el-input v-model="formData.keyword"/>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="24">
                                                <el-form-item label="说明">
                                                    <el-input v-model="formData.description" type="textarea"></el-input>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                    </el-form>
                                </el-tab-pane>
                                <el-tab-pane label="权限信息" name="second">
                                    <div class="checkScrol">
                                        <table class="datatable">
                                            <thead>
                                            <tr>
                                                <th>选择</th>
                                                <th>权限id</th>
                                                <th>权限名称</th>
                                                <th>keyword</th>
                                                <th>权限说明</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <div v-if="pTableData">
                                                <tr v-for="p in pTableData">
                                                    <td>
                                                        <input :id="p.id" v-model="permissionIds" type="checkbox" :value="p.id">
                                                    </td>
                                                    <td><label :for="p.id">{{p.id}}</label></td>
                                                    <td><label :for="p.id">{{p.name}}</label></td>
                                                    <td><label :for="p.id">{{p.keyword}}</label></td>
                                                    <td><label :for="p.id">{{p.description}}</label></td>
                                                </tr>
                                            </div>
                                            <div v-if="pTableData">
                                                <tr>
                                                    <td>
                                                        <input id="pid" v-model="permissionIds" type="checkbox">
                                                    </td>
                                                    <td><label for="pid">p.id</label></td>
                                                    <td><label for="pid">p.name</label></td>
                                                    <td><label for="pid">p.keyword</label></td>
                                                    <td><label for="pid">p.description</label></td>
                                                </tr>
                                            </div>
                                            </tbody>
                                        </table>
                                    </div>
                                </el-tab-pane>
                                <el-tab-pane label="菜单信息" name="third">
                                    <div class="checkScrol">
                                        <table class="datatable">
                                            <thead>
                                            <tr>
                                                <th>选择</th>
                                                <th>菜单id</th>
                                                <th>菜单名称</th>
                                                <th>keyword</th>
                                                <th>菜单说明</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <div v-if="mTableData">
                                                <tr v-for="m in mTableData">
                                                    <td>
                                                        <input :id="m.id" v-model="menuIds" type="checkbox" :value="m.id">
                                                    </td>
                                                    <td><label :for="m.id">{{m.id}}</label></td>
                                                    <td><label :for="m.id">{{m.name}}</label></td>
                                                    <td><label :for="m.id">{{m.keyword}}</label></td>
                                                    <td><label :for="m.id">{{m.description}}</label></td>
                                                </tr>
                                            </div>
                                            <div v-if="mTableData">
                                                <tr>
                                                    <td>
                                                        <input id="mid" v-model="menuIds" type="checkbox">
                                                    </td>
                                                    <td><label for="mid">p.id</label></td>
                                                    <td><label for="mid">p.name</label></td>
                                                    <td><label for="mid">p.keyword</label></td>
                                                    <td><label for="mid">p.description</label></td>
                                                </tr>
                                            </div>
                                            </tbody>
                                        </table>
                                    </div>
                                </el-tab-pane>
                            </el-tabs>
                        </template>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑菜单" :visible.sync="dialogFormVisible4Edit">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                                 label-width="100px">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="角色名称" prop="name">
                                                        <el-input v-model="formData.name"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="keyword" prop="keyword">
                                                        <el-input v-model="formData.keyword"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="24">
                                                    <el-form-item label="说明">
                                                        <el-input v-model="formData.description" type="textarea"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                    <el-tab-pane label="权限信息" name="second">
                                        <div class="checkScrol">
                                            <table class="datatable">
                                                <thead>
                                                <tr>
                                                    <th>选择</th>
                                                    <th>权限id</th>
                                                    <th>权限名称</th>
                                                    <th>keyword</th>
                                                    <th>权限说明</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <div v-if="pTableData">
                                                    <tr v-for="p in pTableData">
                                                        <td>
                                                            <input :id="p.id" v-model="permissionIds" type="checkbox" :value="p.id">
                                                        </td>
                                                        <td><label :for="p.id">{{p.id}}</label></td>
                                                        <td><label :for="p.id">{{p.name}}</label></td>
                                                        <td><label :for="p.id">{{p.keyword}}</label></td>
                                                        <td><label :for="p.id">{{p.description}}</label></td>
                                                    </tr>
                                                </div>
                                                <div v-if="pTableData">
                                                    <tr>
                                                        <td>
                                                            <input id="pid1" v-model="permissionIds" type="checkbox">
                                                        </td>
                                                        <td><label for="pid1">p.id</label></td>
                                                        <td><label for="pid1">p.name</label></td>
                                                        <td><label for="pid1">p.keyword</label></td>
                                                        <td><label for="pid1">p.description</label></td>
                                                    </tr>
                                                </div>
                                                </tbody>
                                            </table>
                                        </div>
                                    </el-tab-pane>
                                    <el-tab-pane label="菜单信息" name="third">
                                        <div class="checkScrol">
                                            <table class="datatable">
                                                <thead>
                                                <tr>
                                                    <th>选择</th>
                                                    <th>菜单id</th>
                                                    <th>菜单名称</th>
                                                    <th>keyword</th>
                                                    <th>菜单说明</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <div v-if="mTableData">
                                                    <tr v-for="m in mTableData">
                                                        <td>
                                                            <input :id="m.id" v-model="menuIds" type="checkbox" :value="m.id">
                                                        </td>
                                                        <td><label :for="m.id">{{m.id}}</label></td>
                                                        <td><label :for="m.id">{{m.name}}</label></td>
                                                        <td><label :for="m.id">{{m.keyword}}</label></td>
                                                        <td><label :for="m.id">{{m.description}}</label></td>
                                                    </tr>
                                                </div>
                                                <div v-if="mTableData">
                                                    <tr>
                                                        <td>
                                                            <input id="mid1" v-model="menuIds" type="checkbox">
                                                        </td>
                                                        <td><label for="mid1">p.id</label></td>
                                                        <td><label for="mid1">p.name</label></td>
                                                        <td><label for="mid1">p.keyword</label></td>
                                                        <td><label for="mid1">p.description</label></td>
                                                    </tr>
                                                </div>
                                                </tbody>
                                            </table>
                                        </div>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                        </el-form>
                        <div slot="footer" class="dialog-footer">
                            <el-button @click="dialogFormVisible = false">取消</el-button>
                            <el-button type="primary" @click="handleAdd()">确定</el-button>
                        </div>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleUpdate()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
            rules: {//校验规则
                code: [{required: true, message: '项目编码为必填项', trigger: 'blur'}],
                name: [{required: true, message: '项目名称为必填项', trigger: 'blur'}]
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();//页面加载完成后 分页查询
        },
        methods: {

            //添加
            handleAdd() {
                this.activeName = "first";
                this.$refs['dataAddForm'].validate((valid) => {
                    // alert(valid);
                    if(valid) {
                        //表单数据this.formData;
                        //提交表单数据
                        axios.post('/checkitem/add.do', this.formData).then(res => {
                            this.dialogFormVisible = false;
                        //成功
                        if (res.data.flag) {
                            //弹出提示
                            this.$message({
                                message: res.data.message,
                                type: 'success'
                            });
                            //刷新页面
                            this.findPage();
                        } else {
                            //提示失败
                            this.$message({
                                message: res.data.message,
                                type: 'error'
                            });
                        }
                    })
                    } else {
                        console.log('error submit!!');
                return false;
            }
            })
                ;

            },
            //分页查询
            findPage() {
                var params = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                }
                //发送请求
                axios.post('/checkitem/findPage.do', params).then(res => {
                    //为模型数据赋值，基于VUE的双向绑定展示到页面
                    this.dataList = res.data.rows;
                this.pagination.total = res.data.total;
            })
            },
            // 重置表单
            resetForm() {
            },
            // 弹出添加窗口
            handleCreate() {
                //弹出窗口
                this.dialogFormVisible = true;
            },
            //编辑
            handleUpdate() {
                this.activeName = "first";
                this.$refs['dataEditForm'].validate((valid) => {
                    // alert(valid);
                    if(valid) {
                        //表单数据this.formData;
                        //提交表单数据
                        axios.post('/checkitem/edit.do', this.formData).then(res => {
                            this.dialogFormVisible4Edit = false;
                        //成功
                        if (res.data.flag) {
                            //弹出提示
                            this.$message({
                                message: res.data.message,
                                type: 'success'
                            });
                            //刷新页面
                            this.findPage();
                        } else {
                            //提示失败
                            this.$message({
                                message: res.data.message,
                                type: 'error'
                            });
                        }
                    })
                    } else {
                        console.log('error submit!!');
                return false;
            }
            })
                ;
            },
            // 弹出编辑窗口
            handleEdit(row) {
                this.activeName = "first";
                //this.dialogFormVisible4Edit =true;
                //跟row.id发送请求获取checkItem对象
                axios.get('/checkitem/findById.do?id=' + row.id).then(res => {
                    if(res.data.flag
            )
                {
                    //设置编辑窗口属性，dialogFormVisible4Edit为true表示显示
                    this.dialogFormVisible4Edit = true;
                    //为模型数据设置值，基于VUE双向数据绑定回显到页面
                    this.formData = res.data.data;
                }
            else
                {
                    this.$message.error("获取数据失败，请刷新当前页面");
                }
            })
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                //发送请求
                this.findPage();
            },
            //权限不足提示
            showMessage(r) {
                if (r == 'Error: Request failed with status code 403') {
                    //权限不足
                    this.$message.error('无访问权限');
                    return;
                } else {
                    this.$message.error('未知错误');
                    return;
                }
            },
            // 删除
            handleDelete(row) {
                //row:对象  JSON.stringify：将对象转成字符串
                //{"age":"0-100","attention":"无","code":"0001","id":28,"name":"身高","price":5,"remark":"身高","sex":"0","type":"1"}
                //alert(row.id);
                //弹出确认提示框
                this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //发送删除请求
                    axios.get('/checkitem/delete.do?id=' + row.id).then(res => {
                        //成功
                        if(res.data.flag
            )
                {
                    this.$message({
                        type: 'success',
                        message: res.data.message
                    });
                    this.findPage();//刷新页面
                }
            else
                {
                    this.$message({
                        type: 'error',
                        message: res.data.message
                    });
                }
            }).
                catch(r => {
                    this.showMessage(r);
            })
            }).
                catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
            })
                ;
            }
        }
    })
</script>
</html>